
<table width="1024" align="center" class="borda">
    <tr>
        <td>Digite um dado para busca:
            <form id="form1" name="form1" method="post" action="?menu=visualizar_departamento">
                <label>
                    <input type="text" size="60" name="texto" id="texto" />
                </label>
                <label> </label>
                <input type="submit" name="buscar" id="buscar"  value="Buscar" />
            </form></td>
    </tr>
    <tr>
        <td height="120">
            <?php
            $nome = $_POST['texto'];
            if (isset($nome)) {
                require_once '../dao/DepartamentoDaoImp.class.php';
                $dao = new DepartamentoDaoImp();
                $result = $dao->buscarNome($nome);
            ?>
                <table width='1024' border="1">
                <?php
                foreach ($result as $row) {
                ?>
                    <tr>
                        <td><?php echo $row['idDepartamento'] ?> </td>
                        <td><?php echo $row['nome'] ?> </td>
                        <td><?php echo $row['sigla'] ?> </td>

                        <!-- func =  1 indica visualizar, func = 2 indica alterar e 3 indica deletar-->
                        <td><a href="?menu=visualizar_departamento&func=1&id=<?php echo $row['idDepartamento'] ?>">Visualizar</a> </td>
                        <td><a href="?menu=visualizar_departamento&func=2&id=<?php echo $row['idDepartamento'] ?>">Alterar</a> </td>
                        <td><a href="?menu=visualizar_departamento&func=3&id=<?php echo $row['idDepartamento'] ?>">Fechar</a> </td>
                    </tr>
                <?php
                }
                ?>
            </table>
            <?php
            }
            ?>
        </td>
    </tr>
</table>

<?php
            $acao = $_GET['func'];
            $id = $_GET['id'];
            if (isset($acao) && isset($id)) {

                require_once '../dao/DepartamentoDaoImp.class.php';
                $dao = new DepartamentoDaoImp();
                $result = $dao->buscarId($id);
?>

<<<<<<< .mine
              <form action="daoDepartamento.php" method="post">
                    <input name="acao" id="acao" type="hidden" value="<?php echo $acao; ?>" />
=======
                <form action="pages/daoDepartamento.php" method="post">

>>>>>>> .r30
                    <table width="1024" valign="top" border="0" align="center">
        <?php
                foreach ($result as $row) {
        ?>
                    <tr>
                        <td height="720" valign="top">
                            <!-- Campos ocultos-->
                            <input name="acao"  type="hidden" value="<?php echo $acao; ?>" />
                            <input name="conta" type="hidden" value="<?php echo $row['conta']; ?>" />
                            <table width="1024" border="0">
                                <tr>
                                    <td width="187" height="43" align="right">Código </td>
                                    <td width="827" ><label>
                                            <input name="id" id="id" type="text"  value="<?php echo $row['idDepartamento']; ?>" width="50" />
                                        </label>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="187" height="43" align="right">Nome*</td>
                                    <td width="827" ><label>
                                            <input name="nome" type="text" value="<?php echo $row['nome'] ?>" width="400" />
                                        </label></td>
                                </tr>
                                <tr>
                                    <td height="43" align="right">Sigla*</td>
                                    <td ><label>
                                            <input name="sigla" type="text" value="<?php echo $row['sigla'] ?>" maxlength="11" />
                                        </label>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="43" align="right">Departamento Superior</td>
                                    <td >
                                        
                                <?php
                                require_once '../dao/DepartamentoDaoImp.class.php';
                                $depDao = new DepartamentoDaoImp;
                                if ($acao == 1) {
                                    echo $nome;
                                
                                    $result = $depDao->buscarDepSuperior($id);
                                    if($result){
                                        $row = $result->fetch(PDO::FETCH_OBJ);

                                ?>
                                        <input type="text" value="<?php echo $row->nomeDepSuperior; ?>" />
                                <?php
                                    }else{
                                        ?>
                                        <input type="text" value=""/>
                                        <?php
                                    }
                                }else{
                                    $result = $depDao->buscarTodos();
                                    ?>
                                <select name="departamentoSup" >
                                    <option value="null">
                                        
                                    </option>
                                    <?php
                                foreach ($result as $row) {
                                ?>
                                    <option value="<?php echo $row['idDepartamento'] ?>">
                                    <?php
                                    echo $row['nome'];
                                    ?>
                                </option>
                                <?php }
                                }?>

                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <?php
                                switch ($acao) {
                                    case 2: {
                                            echo "<input type='submit' value='Alterar' />";
                                            break;
                                        }
                                    case 3: {
                                            echo "<input type='submit' value='Fechar' />";
                                            break;
                                        }
                                    default:break;
                                }
                            ?>

                            </td>
                        </tr>

                    </table></td>
            </tr>
<?php
                            }
?>
                        </table>
                    </form>
<?php
                        }
?>
